import { Component, HostListener, ChangeDetectorRef } from "@angular/core";
import { BaseComponent } from "../../../../../shared/components/baseComponent/base.component";

@Component({
    selector: 'scroll-to-top',
    templateUrl: 'scrollToTop.component.html',
    styleUrls: ['./scrollToTop.component.scss']
})
export class ScrollToTopComponent extends BaseComponent {

    public showScrollToTop: boolean = false;
    @HostListener('window:scroll', [])
    onWindowScroll() {
        if (window.pageYOffset > 135) {
            this.showScrollToTop = true;
        } else {
            this.showScrollToTop = false;
        }
    }

    constructor(
        private cdRef: ChangeDetectorRef) {
        super(cdRef);
    }

    public scrollTop() {
        window.scrollTo({ left: 0, top: 0, behavior: 'smooth' });
    }

}